<template>
	<view class="content">
		<image class="bg" src="https://restaurant-saas.oss-cn-heyuan.aliyuncs.com/upload/20250208/cf7885d058055011addc5864609b1dc1.png"
			mode=""></image>
		<view class="hello">
			Hello
		</view>
		<view class="login">
			欢迎登录
		</view>
		<view class="input-view">
<!-- 			<view class="input-box" style="border-bottom: 1px solid #D8D8D8;">
				<image src="@/static/tenant.png" mode=""></image>
				<input type="text" v-model="data.tenantId" placeholder="请输入租户" />
			</view> -->
			<view class="input-box" style="border-bottom: 1px solid #D8D8D8;">
				<image src="@/static/account.png" mode=""></image>
				<input type="text" v-model="data.account" placeholder="请输入账号" />
			</view>
			<view class="input-box">
				<image src="@/static/password.png" mode=""></image>
				<input type="text" v-model="data.password" :password="true" placeholder="请输入密码" />
			</view>
		</view>
		<view class="margin-box">
			<uv-checkbox-group style="line-height: 40px;">
				<uv-checkbox @change="checkboxChange" v-model="agreementFlag" shape="square"
					label="我已阅读并同意"></uv-checkbox>
			</uv-checkbox-group>
			<view style="width: 120px;">
				<uv-text @click="showChange" color="#2A82E4FF" size="14px" text="《用户隐私协议》">
				</uv-text>
			</view>
		</view>

		<view class="button" @click="GoIndex">
			登录
		</view>
	</view>
</template>

<script>
	import {
		encrypt
	} from '@/utils/sm2'
	import AuthAPI from '@/api/auth'
	import {
		showToast
	} from '@/utils/media';
	export default {
		data() {
			return {
				agreementFlag: false,
				data: {
					tenantId:'100000',
					account:'',
					password:''
				}
			};
		},
		methods: {
			checkboxChange(e) {
				console.info(e)
				this.agreementFlag = e;
			},
			showChange() {
				// #ifdef MP-WEIXIN
				// 打开隐私协议页面
				uni.openPrivacyContract({
					success: () => {}, // 打开成功
					fail: () => {}, // 打开失败
					complete: () => {}
				})
				// #endif
			},
			GoIndex() {
				if (!this.agreementFlag) {
					uni.showToast({
						title: "请先勾选用户隐私协议",
						icon: 'none'
					})
					return
				}
				var data = {
					tenantId:this.data.tenantId,
					account: this.data.account,
					password: encrypt(this.data.password)
				}
        AuthAPI.Login(data).then(res => {
					if (res.code !== 200) {
						showToast({
							title: res.msg
						})
						return
					}
					uni.setStorageSync('accessToken', res.data.accessToken)
					uni.setStorageSync('authInfo',res.data)

          AuthAPI.userInfo().then(res => {
            if (res.code !== 200) {
              return
            }
            this.data =res.data
            uni.setStorageSync('userInfo', res.data)
          })

          uni.reLaunch({
            url: '/pages/index/index'
          })
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;

		.bg {
			top: 0;
			position: absolute;
			z-index: -1;
			width: 100vw;
			height: 100vh;
		}

		.hello {
			margin-top: 300rpx;
			width: 686rpx;
			font-weight: 800;
			font-size: 92rpx;
			color: #202020;
		}

		.login {
			margin-top: 32rpx;
			width: 686rpx;
			font-weight: bold;
			font-size: 50rpx;
			color: #24242E;
		}

		.input-view {
			margin-top: 90rpx;
			width: 686rpx;
			background: #FFF;
			border-radius: 16rpx;
			display: flex;
			flex-direction: column;
			align-items: center;

			.input-box {
				width: 650rpx;
				display: flex;
				align-items: center;
				height: 154rpx;

				>image {
					margin: 0 42rpx 0 62rpx;
					width: 30rpx;
					height: 33rpx;
				}
			}
		}

		.margin-box {

			margin-top: 20rpx;
			display: flex;
		}

		.button {
			margin-top: 70rpx;
			width: 686rpx;
			height: 92rpx;
      background: $custom-btn-color;
			box-shadow: 0rpx 5rpx 13rpx 1rpx rgba(67, 119, 236, 0.44);
			border-radius: 46rpx;
			text-align: center;
			line-height: 92rpx;
			color: #fff;
			font-weight: 500;
			font-size: 32rpx;
		}
	}
</style>